package com.lanchewuyou.user.driver.ui;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.Toast;

import com.lanchewuyou.user.driver.R;
import com.lanchewuyou.user.driver.modul.Config;
import com.lanchewuyou.user.driver.yancheui.YancheFixActivity;

/**
 * 引导页.
 */
public class GuideActivity extends AppCompatActivity implements View.OnClickListener {
    public static String DRIVERID;

    private FrameLayout frameLayoutCar, frameLayoutCar2, frameLayoutMan, frameLayoutSetting;

    private Toast toast1;

    private void showTextToast(String msg) {
        if (toast1 == null) {
            toast1 = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
        } else {
            toast1.setText(msg);
        }
        toast1.show();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);
        SharedPreferences sharedPreferences = getSharedPreferences(Config.PASSWORD_PATH, Activity.MODE_PRIVATE);
        DRIVERID = sharedPreferences.getString("driverid", "");
        initViews();

    }

    private void initViews() {
        frameLayoutCar = (FrameLayout) findViewById(R.id.glide_car1_layout);
        frameLayoutCar.setOnClickListener(this);
        frameLayoutCar2 = (FrameLayout) findViewById(R.id.glide_car2_layout);
        frameLayoutCar2.setOnClickListener(this);
        frameLayoutMan = (FrameLayout) findViewById(R.id.glide_man_layout);
        frameLayoutMan.setOnClickListener(this);
        frameLayoutSetting = (FrameLayout) findViewById(R.id.glide_setting_layout);
        frameLayoutSetting.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.glide_car1_layout:

                break;
            case R.id.glide_car2_layout:
                startActivity(new Intent(this, YancheFixActivity.class));
                break;
            case R.id.glide_man_layout:

                break;
            case R.id.glide_setting_layout:

                break;
            default:
                break;
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }

    private long exitTime;

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if ((System.currentTimeMillis() - exitTime) > 2000) {
                Object mHelperUtils;
                showTextToast("再按一次退出程序");
                exitTime = System.currentTimeMillis();

            } else {
                finish();
            }
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }
}
